package com.yoomiito.app.ui.my;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import com.google.android.material.tabs.TabLayout;
import android.view.View;

import com.yoomiito.app.Constant;
import com.yoomiito.app.R;
import com.yoomiito.app.base.App;
import com.yoomiito.app.model.bean.TabBean;
import com.yoomiito.app.present.my.activity.MyTodayOrderPresenter;
import com.yoomiito.app.ui.fragment.my.MyOrderBaseFragment;
import com.yoomiito.app.ui.fragment.my.MyOrderFragment;
import com.yoomiito.app.ui.fragment.my.MyVipFragment;
import com.yoomiito.app.utils.AllUtils;
import com.yoomiito.app.utils.Const;
import com.yoomiito.app.utils.ResUtil;

import java.util.ArrayList;
import java.util.List;

public class MyTodayOrderActivity extends MyOrderBaseActivity<MyTodayOrderPresenter> {

    private int[] types = {Constant.NAMAL_TYPE_TAOBAO,Constant.NAMAL_TYPE_CREDITCARD,Constant.NAMAL_TYPE_FREEGIFT,Constant.NAMAL_TYPE_GIVEMORE,Constant.NAMAL_TYPE_JINGDONG,Constant.NAMAL_TYPE_GOOD,
            Constant.NAMAL_TYPE_EXPLOSIVE, Constant.NAMAL_TYPE_GIFT,Constant.NAMAL_TYPE_SUBJECT};
    private int position = -1;
    public static void start(Context context,int p) {
        Intent intent = new Intent(context,MyTodayOrderActivity.class);
        intent.putExtra(Const.Common.Position, p);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
    }

    @Override
    public MyTodayOrderPresenter newP() {
        return new MyTodayOrderPresenter(App.mAppConfig);
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        mTabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
        mTabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);

        Intent intent = getIntent();
        if (intent!=null) position = intent.getIntExtra(Const.Common.Position,-1);
        desTv.setVisibility(View.GONE);
        titleView.setCenterText(ResUtil.getString(R.string.my_today_order));
        moneyTv.setTypeface(AllUtils.getTypeface());
        /*
         * 1("1","淘宝"),_2("2","礼包"),_3("3","爆品"),_4("4","优品"),_5("5","99知识付费"),_6("6","送多多礼包"),_7("7","送多多赠品"),_8("8","京东"); 9--信用卡
         */
        if (position!=-1){//8 京东
            mTabLayout.postDelayed(() -> {
                for (int i = 0; i < mTabLayout.getTabCount(); i++) {
                    if (position==(int)mTabLayout.getTabAt(i).getTag()){
                        position = i;
                        break;
                    }
                }
                mTabLayout.getTabAt(position).select();
            }, 100);
        }
    }

    @Override
    protected List<MyOrderBaseFragment> getAllFragment() {
        List<MyOrderBaseFragment> list = new ArrayList<>();
        for (int type:types){
            MyOrderFragment orderFragment = new MyOrderFragment();
            Bundle goodBundle = new Bundle();
            goodBundle.putInt(MyVipFragment.KEY_TYPE,type);
            orderFragment.setArguments(goodBundle);
            list.add(orderFragment);
        }
        return list;
    }

    @Override
    protected List<TabBean> getTabList() {
        List<TabBean> tabs = new ArrayList<>();
        tabs.add(new TabBean(ResUtil.getString(R.string.taobao),0,false,1));
        tabs.add(new TabBean("智能用卡",0,false,9));
        tabs.add(new TabBean("赠品",0,false,7));
        tabs.add(new TabBean("送多多",0,false,6));
        tabs.add(new TabBean("京东",0,false,8));
        tabs.add(new TabBean(ResUtil.getString(R.string.my_good_goods),0,false,4));
        tabs.add(new TabBean(ResUtil.getString(R.string.my_explosive_goods),0,false,3));
        tabs.add(new TabBean(ResUtil.getString(R.string.my_gift_bag),0,false,2));
        tabs.add(new TabBean("课程",0,false,5));
        return tabs;
    }
}
